package com.laker.autotest.webui.page.csdn;


import com.laker.autotest.webui.core.BasePage;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;

/**
 * <p>
 * https://playwright.dev/java/docs/pom
 * 页面对象模型，目的是为了代码维护方便。
 * 以搜索功能为例，搜索页面需要存放元素定位和控件操作行为。
 * csdn 搜索页
 * </p>
 */
public class CsdnSearchPage extends BasePage {
    private static final String URL = "https://so.csdn.net/so/search";
    private final Locator userTab;
    private final Locator followBtn;

    private final Locator searchInput;
    private final Locator searchBtn;

    public CsdnSearchPage(Page page) {
        super(page);
        this.userTab = page.getByText("用户", new Page.GetByTextOptions().setExact(true));
        this.followBtn = page.getByText("关注", new Page.GetByTextOptions().setExact(true));
        searchInput = this.page.locator("#keyword");
        searchBtn = this.page.locator("#search");
    }

    @Override
    protected String initUrl() {
        return URL;
    }


    /**
     * 点击userTab
     */
    public void clickUserTab() {
        userTab.click();
    }


    public void search(String kw) {
        searchInput.fill(kw);
        searchBtn.click();
    }

    public String getSearchResult() {
        return getComponentText(page.getByRole(AriaRole.EMPHASIS));
    }

}